﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;
using _WebShared.Classes;
using KPIS.GERP.GFMS.APP.App_UI.Commons;
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.APP.App_UI.Forms
{
    public partial class FIM_MAS_Banks : System.Web.UI.Page
    {
        Main main = new Main();
        IBLL_FIM_MAS_Banks bank = new B_FIM_MAS_Banks();
        IBLL_FIM_MAS_BankBranchs branch = new B_FIM_MAS_BankBranchs();
        IBLL_FIM_MAS_BankAccountTypes acctype = new B_FIM_MAS_BankAccountTypes();
        IBLL_HRM_MAS_Districts dis = new B_HRM_MAS_Districts();
        IBLL_HRM_MAS_Amphurs amp = new B_HRM_MAS_Amphurs();
        IBLL_HRM_MAS_Provinces prov = new B_HRM_MAS_Provinces();
        IBLL_HRM_MAS_Countries country = new B_HRM_MAS_Countries();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //======= test only =========
                //Session["EmpSeq"] = "1";
                //===========================

                UpdateUI1("ViewAll");
                //UpdateUI2("ViewAll");
                //LoadDDLDistrictSeq();
                //LoadRadGridBankInterestRates("-1");
                //LoadRadGridBankInterestRateHistories("-1", "-1");
                //RadGridBankInterestRates.Enabled = false;
                //RadGridBankInterestRateHistories.Enabled = false;

                string strBankSeq = lblBankSeq.Text;
            }
        }

        protected void SetGridEnable()
        {
            //if (RadGridBanks.SelectedItems.Count == 0)
            //{
            //    RadGridBankInterestRates.Enabled = false;
            //    RadGridBankInterestRateHistories.Enabled = false;
            //    PanelControl2.Enabled = false;
            //}
            //else if (RadGridBankInterestRates.SelectedItems.Count == 0)
            //{
            //    RadGridBankInterestRateHistories.Enabled = false;
            //    PanelControl2.Enabled = false;
            //}
            //else
            //{
            //    RadGridBankInterestRates.Enabled = true;
            //    RadGridBankInterestRateHistories.Enabled = true;
            //    PanelControl2.Enabled = true;
            //}
        }

        protected void LoadRadGridBanks()
        {
            RadGridBanks.DataSource = branch.GetFull();
            //RadGridBanks.DataBind();
        }

        protected IList<M_FIM_MAS_Banks> LoadDDLBankSeq()
        {
            return bank.GetList();
        }

        //protected void LoadRadGridBankInterestRates(string strBankSeq)
        //{
        //    RadGridBankInterestRates.DataSource = rate.GetCurrentInterestRates(strBankSeq);
        //    RadGridBankInterestRates.DataBind();
        //}

        //protected void LoadRadGridBankInterestRateHistories(string strBankSeq, string strBankAccTypeSeq)
        //{
        //    RadGridBankInterestRateHistories.DataSource = rate.GetFull(strBankSeq, null, strBankAccTypeSeq);
        //    RadGridBankInterestRateHistories.DataBind();
        //}

        //protected void LoadRadGrid1(string strBankSeq)
        //{
        //    RadGrid1.DataSource = rate.GetCurrentInterestRates(strBankSeq);
        //    RadGrid1.DataBind();
        //}

        //protected void LoadDDLBankAccTypeSeq()
        //{
        //    ddlBankAccTypeSeq.DataSource = acctype.SelectGrid();
        //    ddlBankAccTypeSeq.DataBind();
        //}

        //protected void LoadDDLDistrictSeq()
        //{
        //    RadTreeView tree = (RadTreeView)ddlDistrictSeq.Items[0].FindControl("treeDistrictSeq");
        //    LoadRootNodes(tree, TreeNodeExpandMode.ServerSideCallBack);
        //}

        private void LoadRootNodes(RadTreeView treeView, TreeNodeExpandMode expandMode)
        {
            IList<M_HRM_MAS_Provinces> ProvInfolist = prov.GetList(null);

            foreach (M_HRM_MAS_Provinces info in ProvInfolist)
            {
                RadTreeNode node = new RadTreeNode();
                node.Text = info.prov_name;
                node.Value = info.prov_seq.ToString();
                node.ExpandMode = expandMode;
                node.Category = "Level0";
                treeView.Nodes.Add(node);
            }
        }

        private void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode)
        {
            switch (e.Node.Category)
            {
                case "Level0":
                    IList<M_HRM_MAS_Amphurs> AmpInfolist = amp.GetList(e.Node.Value);

                    foreach (M_HRM_MAS_Amphurs info in AmpInfolist)
                    {
                        RadTreeNode node = new RadTreeNode();
                        node.Text = info.amp_name;
                        node.Value = info.amp_seq.ToString();
                        node.ExpandMode = expandMode;
                        node.Category = "Level1";
                        e.Node.Nodes.Add(node);
                    }

                    e.Node.Expanded = true;
                    break;
                case "Level1":
                    IList<M_HRM_MAS_Districts> DisInfolist = dis.GetList(e.Node.Value);

                    foreach (M_HRM_MAS_Districts info in DisInfolist)
                    {
                        RadTreeNode node = new RadTreeNode();
                        node.Text = info.district_name;
                        node.Value = info.district_seq.ToString();
                        node.Category = "Level2";
                        e.Node.Nodes.Add(node);
                    }

                    e.Node.Expanded = true;
                    break;
            }
        }

        //protected void LoadDLLCountrySeq()
        //{
        //    ddlCountry.DataSource = country.GetList();
        //    ddlCountry.DataBind();
        //}

        protected void UpdateUI1(string strCommand)
        {
            switch (strCommand)
            {
                case "ViewAll":
                case "Insert":
                case "Update":
                    cmdViewAll1.Visible = false;
                    cmdAddNew1.Visible = true;
                    cmdAddNew12.Visible = true;
                    cmdEdit1.Visible = true;
                    cmdDelete1.Visible = true;
                    cmdInsert1.Visible = false;
                    cmdUpdate1.Visible = false;

                    PanelRadGridBanks.Visible = true;
                    PanelEditBanks.Visible = false;
                    break;
                case "AddNew":
                    cmdViewAll1.Visible = true;
                    cmdAddNew1.Visible = false;
                    cmdAddNew12.Visible = false;
                    cmdEdit1.Visible = false;
                    cmdDelete1.Visible = false;
                    cmdInsert1.Visible = true;
                    cmdUpdate1.Visible = false;

                    PanelRadGridBanks.Visible = false;
                    PanelEditBanks.Visible = true;
                    break;
                case "Edit":
                    cmdViewAll1.Visible = true;
                    cmdAddNew1.Visible = false;
                    cmdAddNew12.Visible = false;
                    cmdEdit1.Visible = false;
                    cmdDelete1.Visible = false;
                    cmdInsert1.Visible = false;
                    cmdUpdate1.Visible = true;

                    PanelRadGridBanks.Visible = false;
                    PanelEditBanks.Visible = true;
                    break;
            }
        }

        //protected void UpdateUI2(string strCommand)
        //{
        //    switch (strCommand)
        //    {
        //        case "ViewAll":
        //        case "Insert":
        //        case "Update":
        //            cmdViewAll2.Visible = false;
        //            cmdAddNew2.Visible = true;
        //            cmdEdit2.Visible = true;
        //            cmdDelete2.Visible = true;
        //            cmdInsert2.Visible = false;
        //            cmdUpdate2.Visible = false;

        //            PanelRadGridBankInterestRateHistories.Visible = true;
        //            PanelEditBankInterestRateHistories.Visible = false;
        //            PanelAdd.Visible = false;
        //            PanelControl1.Enabled = true;
        //            PanelRadGridBanks.Enabled = true;
        //            RadGridBankInterestRates.Enabled = true;
        //            break;
        //        case "AddNew":
        //            cmdViewAll2.Visible = true;
        //            cmdAddNew2.Visible = false;
        //            cmdEdit2.Visible = false;
        //            cmdDelete2.Visible = false;
        //            cmdInsert2.Visible = true;
        //            cmdUpdate2.Visible = false;

        //            PanelRadGridBankInterestRateHistories.Visible = false;
        //            PanelEditBankInterestRateHistories.Visible = false;
        //            PanelAdd.Visible = true;
        //            PanelControl1.Enabled = false;
        //            PanelRadGridBanks.Enabled = false;
        //            RadGridBankInterestRates.Enabled = false;
        //            break;
        //        case "Edit":
        //            cmdViewAll2.Visible = true;
        //            cmdAddNew2.Visible = false;
        //            cmdEdit2.Visible = false;
        //            cmdDelete2.Visible = false;
        //            cmdInsert2.Visible = false;
        //            cmdUpdate2.Visible = true;

        //            PanelRadGridBankInterestRateHistories.Visible = false;
        //            PanelEditBankInterestRateHistories.Visible = true;
        //            PanelAdd.Visible = false;
        //            PanelControl1.Enabled = false;
        //            PanelRadGridBanks.Enabled = false;
        //            RadGridBankInterestRates.Enabled = false;
        //            break;
        //    }
        //}

        protected void ClearControl1()
        {
            lblBankSeq.Text = "";
            lblBranchSeq.Text = "";
            txtBankID.Text = "";
            txtBankName.Text = "";
            txtBankNameEng.Text = "";
            txtBranchID.Text = "";
            txtBranchName.Text = "";
            txtBranchNameEng.Text = "";
            //txtAddress.Text = "";
            //ddlDistrictSeq.SelectedIndex = -1;
            //ddlCountry.SelectedIndex = -1;
        }

        //protected void ClearControl2()
        //{
        //    lblInterestBankName.Text = "";
        //    lblInterestRateSeq.Text = "";
        //    lblInterestBankSeq.Text = "";
        //    lblInterestBranchSeq.Text = "";
        //    lblBankAccTypeSeq.Text = "";
        //    lblBankAccTypeName.Text = "";
        //    txtInterestRate.Text = "";
        //    txtChangeDate.Text = "";
        //}

        //============================ control events ==============================

        protected void RadGridBanks_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick" && e.Item is GridDataItem)
            {
                e.Item.Selected = true;
                string strBankSeq = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["bank_seq"].Text;
                Session["BankSeq"] = strBankSeq;
                //RadGridBankInterestRates.Enabled = true;
                ////PanelControl2.Enabled = true;
                //LoadRadGridBankInterestRates(strBankSeq);
            }
        }

        //protected void BankInterestRates_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    if (e.CommandName == "Sort" || e.CommandName == "Filter")
        //    {
        //        //LoadRadGridBankInterestRates(Session["BankSeq"].ToString());
        //    }
        //    else if (e.CommandName == "RowClick" && e.Item is GridDataItem)
        //    {
        //        e.Item.Selected = true;
        //        string strBankAccTypeSeq = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["bank_acc_type_seq"].Text;
        //        Session["BankAccTypeSeq"] = strBankAccTypeSeq;
        //        RadGridBankInterestRateHistories.Enabled = true;
        //        PanelControl2.Enabled = true;
        //        LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), strBankAccTypeSeq);
        //    }
        //    //RadGridBankInterestRates.DataBind();
        //}

        //protected void BankInterestRateHistories_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    if (e.CommandName == "Sort" || e.CommandName == "Filter")
        //    {
        //        LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), Session["BankAccTypeSeq"].ToString());
        //    }
        //    //RadGridBankInterestRates.DataBind();
        //}

        //protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    if (e.CommandName == "Sort" || e.CommandName == "Filter")
        //    {
        //        LoadRadGrid1(Session["BankSeq"].ToString());
        //    }
        //    //RadGridBankInterestRates.DataBind();
        //}

        protected void RadGridBanks_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                LoadRadGridBanks();
            }
        }

        protected void cmdViewAll1_Click(object sender, EventArgs e)
        {
            UpdateUI1("ViewAll");
            ClearControl1();
        }

        protected void cmdAddNew1_Click(object sender, EventArgs e)
        {
            UpdateUI1("AddNew");

            //LoadDLLCountrySeq();

            txtBankID.Enabled = true;
            txtBankName.Enabled = true;
        }

        protected void cmdAddNew12_Click(object sender, EventArgs e)
        {
            if (RadGridBanks.SelectedItems.Count > 0)
            {
                UpdateUI1("AddNew");

                //LoadDLLCountrySeq();

                string strBankSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_seq"].Text;
                string strBankID = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_id"].Text;
                string strBankName = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_name"].Text;
                string strBankNameEng = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_name_eng"].Text;

                lblBankSeq.Text = main.WebString(strBankSeq);
                txtBankID.Text = main.WebString(strBankID);
                txtBankName.Text = main.WebString(strBankName);
                txtBankNameEng.Text = main.WebString(strBankNameEng);

                txtBankID.Enabled = false;
                txtBankName.Enabled = false;
                txtBankNameEng.Enabled = false;
            }
            else
            {
                main.MessageAlert(Page, "กรุณาเลือกรายการธนาคารที่ต้องการเพิ่มสาขา");
            }
        }

        protected void cmdEdit1_Click(object sender, EventArgs e)
        {
            if (RadGridBanks.SelectedItems.Count > 0)
            {
                UpdateUI1("Edit");

                string strBankSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_seq"].Text;
                string strBranchSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["branch_seq"].Text;
                string strBankID = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_id"].Text;
                string strBankName = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_name"].Text;
                string strBankNameEng = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_name_eng"].Text;
                string strBranchID = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["branch_id"].Text;
                string strBranchName = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["branch_name"].Text;
                string strBranchNameEng = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["branch_name_eng"].Text;
                string strAddress = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["address"].Text;
                string strDistrictSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["district_seq"].Text;
                string strDistrictText = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["district_text"].Text;
                string strCountrySeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["country_seq"].Text;

                //LoadDLLCountrySeq();

                lblBankSeq.Text = main.WebString(strBankSeq);
                lblBranchSeq.Text = main.WebString(strBranchSeq);
                txtBankID.Text = main.WebString(strBankID);
                txtBankName.Text = main.WebString(strBankName);
                txtBankNameEng.Text = main.WebString(strBankNameEng);
                txtBranchID.Text = main.WebString(strBranchID);
                txtBranchName.Text = main.WebString(strBranchName);
                txtBranchNameEng.Text = main.WebString(strBranchNameEng);
                //txtAddress.Text = main.WebString(strAddress);
                //ddlDistrictSeq.Text = main.WebString(strDistrictText);
                //txtDistrictSeq.Text = main.WebString(strDistrictSeq);
                //ddlCountry.SelectedValue = main.WebString(strCountrySeq);

                txtBankID.Enabled = true;
                txtBankName.Enabled = true;
            }
            else
            {
                main.MessageAlert(Page, "กรุณาเลือกรายการที่ต้องการแก้ไข");
            }
        }

        protected void cmdDelete1_Click(object sender, EventArgs e)
        {
            if (RadGridBanks.SelectedItems.Count > 0)
            {
                M_FIM_MAS_BankBranchs info = new M_FIM_MAS_BankBranchs();
                string strUserID = Session["EmpSeq"].ToString();
                DateTime dtNow = DateTime.Now;
                string strBranchSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["branch_seq"].Text;

                info.branch_seq = Convert.ToInt32(strBranchSeq);

                info.updated_by = main.ConvertNullInt(strUserID);
                info.updated_when = main.ConvertNullDateTime(dtNow);

                branch.Delete(info);

                LoadRadGridBanks();
                RadGridBanks.DataBind();
            }
        }

        protected void cmdInsert1_Click(object sender, EventArgs e)
        {
            M_FIM_MAS_Banks bankinfo = new M_FIM_MAS_Banks();
            M_FIM_MAS_BankBranchs BankBranchinfo = new M_FIM_MAS_BankBranchs();
           
            string strBankSeq = lblBankSeq.Text;
            string strBankID = txtBankID.Text;
            string strBankName = txtBankName.Text;
            string strBankNameEng = txtBankNameEng.Text;
            string strBranchID = txtBranchID.Text;
            string strBranchName = txtBranchName.Text;
            string strBranchNameEng = txtBranchNameEng.Text;
            //string strAddress = txtAddress.Text;
            //string strDistrictSeq = (ddlDistrictSeq.Text.Length > 0 ? txtDistrictSeq.Text : "");
            //string strCountrySeq = ddlCountry.SelectedValue;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            //bankinfo.bank_seq = Convert.ToInt32(strBankSeq);
            bankinfo.bank_id = strBankID;
            bankinfo.bank_name = strBankName;
            bankinfo.bank_name_eng = strBankNameEng;
            bankinfo.created_by = main.ConvertNullInt(strUserID);
            bankinfo.created_when = main.ConvertNullDateTime(dtNow);

            if (txtBankID.Enabled)
            {
                strBankSeq = bank.Insert(bankinfo).ToString();

                //strBankSeq = bank.SelectRecentInsertedRoleSeq();
            }

            BankBranchinfo.branch_id = strBranchID;
            BankBranchinfo.branch_name = strBranchName;
            BankBranchinfo.branch_name_eng = strBranchNameEng;
            BankBranchinfo.bank_seq = Convert.ToInt32(strBankSeq);
            //BankBranchinfo.address = strAddress;
            //BankBranchinfo.district_seq = main.ConvertNullInt(strDistrictSeq);
            //BankBranchinfo.country_seq = main.ConvertNullInt(strCountrySeq);
            BankBranchinfo.created_by = main.ConvertNullInt(strUserID);
            BankBranchinfo.created_when = main.ConvertNullDateTime(dtNow);

            branch.Insert(BankBranchinfo);

            LoadRadGridBanks();
            RadGridBanks.DataBind();
            UpdateUI1("Insert");
            ClearControl1();
            SetGridEnable();
        }

        protected void cmdUpdate1_Click(object sender, EventArgs e)
        {
            M_FIM_MAS_Banks bankinfo = new M_FIM_MAS_Banks();
            M_FIM_MAS_BankBranchs BankBranchinfo = new M_FIM_MAS_BankBranchs();
            string strBankSeq = lblBankSeq.Text;
            string strBranchSeq = lblBranchSeq.Text;
            string strBankID = txtBankID.Text;
            string strBankName = txtBankName.Text;
            string strBankNameEng = txtBankNameEng.Text;
            string strBranchID = txtBranchID.Text;
            string strBranchName = txtBranchName.Text;
            string strBranchNameEng = txtBranchNameEng.Text;
            //string strAddress = txtAddress.Text;
            //string strDistrictSeq = (ddlDistrictSeq.Text.Length > 0 ? txtDistrictSeq.Text : "");
            //string strCountrySeq = ddlCountry.SelectedValue;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            bankinfo.bank_seq = Convert.ToInt32(strBankSeq);
            bankinfo.bank_id = strBankID;
            bankinfo.bank_name = strBankName;
            bankinfo.bank_name_eng = strBankNameEng;
            bankinfo.updated_by = main.ConvertNullInt(strUserID);
            bankinfo.updated_when = main.ConvertNullDateTime(dtNow);

            BankBranchinfo.branch_seq = Convert.ToInt32(strBranchSeq);
            BankBranchinfo.branch_id = strBranchID;
            BankBranchinfo.branch_name = strBranchName;
            BankBranchinfo.branch_name_eng = strBranchNameEng;
            BankBranchinfo.bank_seq = Convert.ToInt32(strBankSeq);
            //BankBranchinfo.address = strAddress;
            //BankBranchinfo.district_seq = main.ConvertNullInt(strDistrictSeq);
            //BankBranchinfo.country_seq = main.ConvertNullInt(strCountrySeq);
            BankBranchinfo.updated_by = main.ConvertNullInt(strUserID);
            BankBranchinfo.updated_when = main.ConvertNullDateTime(dtNow);

            bank.Update(bankinfo);

            branch.Update(BankBranchinfo);

            LoadRadGridBanks();
            RadGridBanks.DataBind();
            UpdateUI1("Update");
            ClearControl1();
            SetGridEnable();
        }

        //protected void cmdViewAll2_Click(object sender, EventArgs e)
        //{
        //    UpdateUI2("ViewAll");

        //    ClearControl2();
        //}

        //protected void cmdAddNew2_Click(object sender, EventArgs e)
        //{
        //    UpdateUI2("AddNew");

        //    LoadRadGrid1(RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_seq"].Text);
        //}

        //protected void cmdEdit2_Click(object sender, EventArgs e)
        //{
        //    if (RadGridBankInterestRateHistories.SelectedItems.Count > 0)
        //    {
        //        UpdateUI2("Edit");

        //        string strInterestRateSeq = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["interest_rate_seq"].Text;
        //        string strBankSeq = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["bank_seq"].Text;
        //        string strBranchSeq = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["branch_seq"].Text;
        //        string strBankName = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["bank_name"].Text;
        //        string strBankAccTypeSeq = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["bank_acc_type_seq"].Text;
        //        string strBankAccTypeName = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["bank_acc_type_name"].Text;
        //        string strInterestRate = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["interest_rate"].Text;
        //        string strChangeDate = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["change_date"].Text;

        //        lblInterestRateSeq.Text = main.WebString(strInterestRateSeq);
        //        lblInterestBankSeq.Text = main.WebString(strBankSeq);
        //        lblInterestBranchSeq.Text = main.WebString(strBranchSeq);
        //        lblInterestBankName.Text = main.WebString(strBankName);
        //        lblBankAccTypeSeq.Text = main.WebString(strBankAccTypeSeq);
        //        lblBankAccTypeName.Text = main.WebString(strBankAccTypeName);
        //        txtInterestRate.Text = main.WebString(strInterestRate);
        //        txtChangeDate.Text = main.WebString(strChangeDate);
        //    }
        //    else
        //    {
        //    }
        //}

        //protected void cmdDelete2_Click(object sender, EventArgs e)
        //{
        //    if (RadGridBankInterestRates.SelectedItems.Count > 0)
        //    {
        //        M_FIM_MAS_BankInterestRates info = new M_FIM_MAS_BankInterestRates();
        //        string strUserID = Session["EmpSeq"].ToString();
        //        DateTime dtNow = DateTime.Now;
        //        string strPK = RadGridBankInterestRateHistories.Items[RadGridBankInterestRateHistories.SelectedItems[0].ItemIndex]["interest_rate_seq"].Text;

        //        info.interest_rate_seq = Convert.ToInt32(strPK);
        //        info.updated_by = main.ConvertNullInt(strUserID);
        //        info.updated_when = main.ConvertNullDateTime(dtNow);

        //        rate.Delete(info);

        //        LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), Session["BankAccTypeSeq"].ToString());
        //        RadGridBankInterestRateHistories.DataBind();
        //    }            
        //}

        //protected void cmdInsert2_Click(object sender, EventArgs e)
        //{
        //    GridDataItem item;
        //    string strBankSeq;
        //    string strBranchSeq;
        //    string strBankAccTypeSeq;
        //    string strInterestRate;
        //    string strChangeDate;
        //    string strUserID = Session["EmpSeq"].ToString();
        //    DateTime dtNow = DateTime.Now;

        //    for (int i = 0; i < RadGrid1.Items.Count; i++)
        //    {
        //        M_FIM_MAS_BankInterestRates info = new M_FIM_MAS_BankInterestRates();
        //        item = RadGrid1.Items[i];

        //        strBankSeq = RadGridBanks.Items[RadGridBanks.SelectedItems[0].ItemIndex]["bank_seq"].Text; //main.WebString(item["bank_seq"].Text);
        //        strBranchSeq = main.WebString(item["branch_seq"].Text);
        //        strBankAccTypeSeq = main.WebString(item["bank_acc_type_seq"].Text);
        //        RadMaskedTextBox mask = (RadMaskedTextBox)item.FindControl("gridtxtChangeDate");
        //        strChangeDate = (mask.Text.Length > 0 ? mask.TextWithLiterals.Trim() : "");
        //        strInterestRate = ((RadNumericTextBox)item.FindControl("gridtxtInterestRate")).Text;

        //        info.bank_seq = Convert.ToInt32(strBankSeq);
        //        info.branch_seq = main.ConvertNullInt(strBranchSeq);
        //        info.bank_acc_type_seq = main.ConvertNullInt(strBankAccTypeSeq);
        //        info.interest_rate = main.ConvertNullDouble(strInterestRate);
        //        info.change_date = main.ConvertNullDateTime(strChangeDate);

        //        info.created_by = main.ConvertNullInt(strUserID);
        //        info.created_when = main.ConvertNullDateTime(dtNow);

        //        rate.Insert(info);
        //    }

        //    LoadRadGridBankInterestRates(Session["BankSeq"].ToString());
        //    RadGridBankInterestRates.DataBind();
        //    LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), Session["BankAccTypeSeq"].ToString());
        //    RadGridBankInterestRateHistories.DataBind();
        //    UpdateUI2("Insert");
        //    ClearControl2();
        //    SetGridEnable();
        //}

        //protected void cmdUpdate2_Click(object sender, EventArgs e)
        //{
        //    M_FIM_MAS_BankInterestRates info = new M_FIM_MAS_BankInterestRates();
        //    string strInterestRateSeq = lblInterestRateSeq.Text;
        //    string strBankSeq = lblInterestBankSeq.Text;
        //    string strBranchSeq = lblInterestBranchSeq.Text;
        //    string strBankAccTypeSeq = lblBankAccTypeSeq.Text;
        //    string strInterestRate = txtInterestRate.Text;
        //    string strChangeDate = (txtChangeDate.Text.Length > 0 ? txtChangeDate.TextWithLiterals.Trim() : "");
        //    string strUserID = Session["EmpSeq"].ToString();
        //    DateTime dtNow = DateTime.Now;

        //    info.interest_rate_seq = Convert.ToInt32(strInterestRateSeq);
        //    info.bank_seq = Convert.ToInt32(strBankSeq);
        //    info.branch_seq = main.ConvertNullInt(strBankSeq);
        //    info.bank_acc_type_seq = main.ConvertNullInt(strBankAccTypeSeq);
        //    info.interest_rate = main.ConvertNullDouble(strInterestRate);
        //    info.change_date = main.ConvertNullDateTime(strChangeDate);
            
        //    info.updated_by = main.ConvertNullInt(strUserID);
        //    info.updated_when = main.ConvertNullDateTime(dtNow);

        //    rate.Update(info);

        //    LoadRadGridBankInterestRates(Session["BankSeq"].ToString());
        //    RadGridBankInterestRates.DataBind();
        //    LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), Session["BankAccTypeSeq"].ToString());
        //    RadGridBankInterestRateHistories.DataBind();
        //    UpdateUI2("Update");
        //    ClearControl2();
        //    SetGridEnable();
        //}

        protected void CheckDateValid(object source, ServerValidateEventArgs args)
        {
            if (!DateTimeX.IsValidDmyDate(args.Value, true) || args.Value == "")
            {
                args.IsValid = false;
            }
        }

        protected void treeDistrictSeq_NodeExpand(object sender, RadTreeNodeEventArgs e)
        {
            PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSideCallBack);
        }

        //protected void RadGridBankInterestRateHistories_PageIndexChanged(object source, GridPageChangedEventArgs e)
        //{
        //    LoadRadGridBankInterestRateHistories(Session["BankSeq"].ToString(), Session["BankAccTypeSeq"].ToString());
        //}

        //==========================================================================
    }
}
